package cn.iocoder.yudao.module.member.fans.dal.mysql;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.fans.dal.dataobject.MemberFansDO;
import cn.iocoder.yudao.module.member.fans.vo.MemberFansPageReqVO;
import jakarta.annotation.Nonnull;
import org.apache.ibatis.annotations.Mapper;

/**
 * 粉丝 Mapper
 *
 * @author 山野羡民
 */
@Mapper
public interface MemberFansMapper extends CoreMapper<MemberFansDO> {

    default PageResult<MemberFansDO> selectFansPage(@Nonnull MemberFansPageReqVO reqVO) {
        return selectPage(reqVO, new CoreLambdaQueryWrapper<MemberFansDO>()
                .eqIfPresent(MemberFansDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberFansDO::getFriend, reqVO.getFriend())
                .betweenIfPresent(MemberFansDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberFansDO::getId));
    }

    default PageResult<MemberFansDO> selectFansPage(@Nonnull PageParam page, Long userId) {
        if (userId == null || userId <= 0) {
            return PageResult.empty();
        }
        return selectPage(page, new CoreLambdaQueryWrapper<MemberFansDO>()
                .eq(MemberFansDO::getUserId, userId)
                .orderByDesc(MemberFansDO::getId));
    }


    default PageResult<MemberFansDO> selectFollowPage(@Nonnull PageParam page, Long userId) {
        if (userId == null || userId <= 0) {
            return PageResult.empty();
        }
        return selectPage(page, new CoreLambdaQueryWrapper<MemberFansDO>()
                .eq(MemberFansDO::getFansUserId, userId)
                .orderByDesc(MemberFansDO::getId));
    }

    default PageResult<MemberFansDO> selectFriendPage(@Nonnull PageParam page, Long userId) {
        if (userId == null || userId <= 0) {
            return PageResult.empty();
        }
        return selectPage(page, new CoreLambdaQueryWrapper<MemberFansDO>()
                .eq(MemberFansDO::getFansUserId, userId)
                .eq(MemberFansDO::getFriend, Boolean.TRUE)
                .orderByDesc(MemberFansDO::getId));
    }

}
